package com.bitejiuyeke.forum.controller;

import com.bitejiuyeke.forum.common.AppResult;
import com.bitejiuyeke.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 666
 * Date: 2023-11-03
 * Time: 20:49
 */
@Api(tags = "测试类的相关接口")
// 表示返回的结果是数据
@RestController
@RequestMapping("/test")
public class TestController {
    @ApiOperation("测试接口一")
    @GetMapping("/hello")
        public  String  hello(){
        return "hello ,spring boot";
    }
    @ApiOperation("测试接口二")
    @GetMapping("/exception")
    public String testException() throws Exception {
        throw new Exception("这是⼀个Exception");
    }
    @PostMapping("/helloByName")
    @ApiOperation("测试传入姓名")
    public AppResult helloByName(@ApiParam("姓名")@RequestParam("name") String name){
        return AppResult.success(name);
    }
    @GetMapping("/appException")
    public String testApplicationException() {
        throw new ApplicationException("这是⼀个⾃定义的ApplicationException");
    }
}
